package org.osgroup.controller;

import org.osgroup.service.RollerCoasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 激流勇进项目监控接口
 */
@RestController
@RequestMapping("/api/project/roller-coaster")
@CrossOrigin(origins = "*")
public class RollerCoasterController {
    
    @Autowired
    private RollerCoasterService rollerCoasterService;
    
    /**
     * 获取设备状态
     */
    @GetMapping("/equipment")
    public ResponseEntity<Map<String, Object>> getEquipmentStatus() {
        try {
            // 直接返回设备状态,不嵌套在 "equipment" 字段中
            Map<String, Object> equipment = rollerCoasterService.getRollerCoaster().getEquipmentStatus();
            return ResponseEntity.ok(equipment);
        } catch (Exception e) {
            return ResponseEntity.status(500).build();
        }
    }
    
    /**
     * 获取排队信息
     */
    @GetMapping("/queue")
    public ResponseEntity<Map<String, Object>> getQueueInfo() {
        try {
            Map<String, Object> response = new HashMap<>();
            response.put("queueCount", rollerCoasterService.getRollerCoaster().getQueueCount());
            response.put("waitTime", rollerCoasterService.getRollerCoaster().getEstimatedWaitTime());
            response.put("status", rollerCoasterService.getRollerCoaster().getProjectStatus());
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            return ResponseEntity.status(500).build();
        }
    }
}
